---@class BuffEffect46 : BaseBuffEffect
BuffEffect46 = ClientFight.CreateClass("BuffEffect46", ClientFight.BaseBuffEffect)
local t = BuffEffect46

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = { ... }
    local source = buff.source
    local target = buff.target
    if (target:isDie()) then
        return IBuffEffect.FAIL;
    end
    if (FighterStateEnum.is(buff.target,FighterStateEnum.BAN_HEAL)) then
        return IBuffEffect.FAIL;
    end
    local type = 0;
    local value = 0;
    local f_BuffEffectValue = buff.buffBean.f_BuffEffectValue;
    if (f_BuffEffectValue ~= nil and #f_BuffEffectValue > 0) then
        type = math.floor( f_BuffEffectValue[1])
        value = math.floor(f_BuffEffectValue[2])
    else
        type = buff.addParameters[1];
        value = buff.addParameters[2];
    end

    local addHp = 0;
    if (type == 1) then
        addHp = value;
    elseif type == 2 then
        addHp = math.floor(target.hp * Utils.toRatio(value));
    elseif type == 3 then
        local maxHp = FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
        addHp =  math.floor(maxHp * Utils.toRatio(value));
    elseif type == 4 then
        local maxHp = FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
        local currHp = targethp;
        addHp = math.floor((maxHp - currHp) * Utils.toRatio(value));
    else
        return ClientFight.BaseBuffEffect.action(fight, buff, ...);
    end

    local maxHp = FighterAttributeManager.getFightAttr(target, FighterAttributeEnum.HP);
    if (maxHp - target.hp < addHp) then
        addHp = maxHp - target.hp;
        if (addHp < 0) then
            addHp = 0;
        end
    end
    --local logAddHp = addHp;
        --LogUtil.info(fight, ()->
        --"[" + fightframe + "][EFFECT]Fighter " + buff.targetfighterId + " Buff"
        --+ buffmodelId + " 触发回血:" + logAddHp);
    DamageManager.setFighterHp(fight, target, source, nil, DamageResultTypeEnum.HEAL,
    addHp, target.hp + addHp, true, true, true);

    return ClientFight.BaseBuffEffect.action(self,fight, buff, ...);
end

t.New()